﻿@{
    Style.Require("jQueryUI_Orchard");
    Style.Require("NineSeas.Common");
    Style.Require("NineSeas.Reader");
    Style.Require("NineSeas.Authoring");
    Style.Require("NineSeas.Book.Chapters");

    Script.Require("NineSeas.Common");
    Script.Require("NineSeas.CommandBar");

    var pager = New.Pager(Model.Paging).TotalItemCount(Model.Paging.TotalRecords);
}
<div id="nineseas">
    <div id="nineseas-reader-header">
        <div class="header-bullet"></div>
        <h1>@Model.Book.Name</h1>
    </div>
    <div id="nineseas-reader-content">
        <div id="content-area">
            <div class="chapters-container">
                <div class="nineseas-commands-right">
                    <a href="@Url.Action("Create", "Chapter", new { bookId = Model.Book.Id})">
                            @T("Create new")
                    </a>  
                </div>
                <h1>@T("Table of content")</h1>   
                <div style="clear: both; margin-top: 10px;"></div>
                
                @if (Model.Chapters.Count == 0) {         
                    <p>@T("This book don't have any chapter.")</p>
                } else { 
                    <div class="chapter-items">               
                    @for (var i = 0; i < Model.Chapters.Count; i++)
                    {
                        dynamic chapter = Model.Chapters[i];
                    <div class="chapter-item @(i % 2 == 0 ? "" : "chapter-item-alternate")">
                        <a href="@Url.Action("Delete", "Chapter", new {id = chapter.Id, ReturnUrl = Request.Url.PathAndQuery})" class="command-right delete" onclick="return confirm('@T("Are you sure you want to delete this chapter?")')">
                            @T("Delete")
                        </a>
                        <a href="@Url.Action("MoveUp", "Chapter", new {id = chapter.Id})" class="command-right arrow-up">
                            @T("Move Up")
                        </a>
                        <a href="@Url.Action("MoveDown", "Chapter", new {id = chapter.Id})" class="command-right arrow-down">
                            @T("Move Down")
                        </a>
                        <a href="@Url.Action("Edit", "Chapter", new {id = chapter.Id})" class="chapter-title authoring">
                            @(!String.IsNullOrEmpty(chapter.Title) ? (chapter.SortOrder + 1) + ". " + chapter.Title : T("Chapter").Text + " " + (chapter.SortOrder + 1))
                        </a>
                        @if (!chapter.ContentItem.VersionRecord.Published)
                        {
                            @Display(New.Controls_HelpPopup(Message: T("Unpublished")))
                        }
                        <div class="clear: both;"></div>     
                    </div>
                    }  
                    </div>  
                }
                <div class="clear: both;"></div>
            </div>            
            @Display(pager)
        </div>
    </div>
    <div id="nineseas-reader-footer"></div>
</div>
@using (Script.Foot()) {
<script type="text/javascript">
    //<![CDATA[
    $(function () {
        var bookDetailsButton = {
            id: 'bookDetailsButton',
            caption: '&lt; @T("Back to book details")',
            type: 'a',
            href: '@Url.Action("Edit", "Books", new {Model.Book.Id})'
        };
        $.commandBar('#nineseas-reader-footer', {
            left: [
                bookDetailsButton
            ],
            right: []
        });
    });
    //]]>
</script>
}
